/*Source

Problem Id:2694  User Id:Latex 
Memory:72K  Time:0MS
Language:G++  Result:Accepted

Source 
*/
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <cstdlib>
using namespace std;

char ss[7][5];
char suit[7];
int  num[7];
int n;
int tot[21];
int score;

int getnum(char ch)
{	
	if (ch=='A') return 1;
	if (ch>='1' && ch<='9') return ch-'0';
	if (ch=='X') return 10;
	if (ch=='J') return 11;
	if (ch=='Q') return 12;
	if (ch=='K') return 13;
}
void getsuit()
{
	int i;
	for (i=1; i<=5; ++i)
	{	
		suit[i] = toupper(ss[i][0]);		
		num[i] = getnum(toupper(ss[i][1]));
		
	}
	/*/
	for (i=1; i<=5; ++i)
		printf("%c", suit[i]);
	printf("\n");
	for (i=1; i<=5; ++i)
		printf("%d", num[i]);
	printf("\n");*/
}
bool issuit()
{
	int i;	
	for (i=2; i<=5; ++i)
		if (suit[1] != suit[i])
			return false;
	return true;
}
bool isseq()
{
	int i;
	sort(num+1, num+6);
/*	if (num[1] == 1)
	{
		for (i=1; i<=5; ++i)
			if (num[i]>=6 && num[i]<=9) return false;
		for (i=1; i<=5; ++i)
			if (num[i]>=1 && num[i]<=5)
				num[i]+=13;
	}*/
	if (num[1] == 1)
	{
		for (i=2; i<=5; ++i)
			if (num[i]>5) 
			{	
				num[1] = 14;
				break;
			}
	}
	sort(num+1, num+6);
	for (i=1; i<5; ++i)
		if (num[i+1] - num[i] != 1)
			return false;
	return true;
}

void gettot()
{
	int i;
	memset(tot, 0, sizeof(tot));
	for (i=1; i<=5; ++i)
		tot[num[i]]++;
}
bool is750()
{
	int i;
	for (i=1; i<20; ++i)
		if (tot[i] == 4) return true;
	return false;
}
bool is500()
{
	int i;
	bool f2,f3;
	f2 = f3 = false;
	for (i=1; i<20; ++i)
	{
		if (tot[i] == 2) f2 = true;
		if (tot[i] == 3) f3 = true;
	}
	if (f2 && f3) return true;
	return false;
}
bool is200()
{
	int i;
	for (i=1; i<20; ++i)
		if (tot[i] == 3) return true;
	return false;
}
bool is100()
{
	int i, j;
	j = 0;
	for (i=1; i<20; ++i)
		if (tot[i] == 2) j++;
	if (j==2) return true;
	return false;
}
bool is50()
{
	int i, j;
	j = 0;
	for (i=1; i<20; ++i)
		if (tot[i] == 2) j++;
	if (j==1) return true;
	return false;
}

void count()
{
	bool fsuit, fseq;
	fsuit = issuit();
	fseq = isseq();
	if (fsuit && fseq) 
	{
		score = 1000;
		return;
	}
	if (is750())
	{
		score = 750;
		return;
	}
	if (is500())
	{
		score = 500;
		return;
	}
	if (fsuit)
	{
		score = 350;
		return;
	}
	if (fseq)
	{
		score = 250;
		return;
	}
	if (is200())
	{
		score = 200;
		return;
	}
	if (is100())
	{
		score = 100;
		return;
	}
	if (is50())
	{
		score = 50;
		return;
	}
	score=0;
}

int main()
{
	int i;
	
	scanf("%d", &n);
	while (n--)
	{
		memset(ss,0,sizeof(ss));
		for (i=1; i<=5; ++i)
			scanf("%s", ss[i]);
		getsuit();
		gettot();
		score = 0;
		count();
		printf("%d\n", score);
	}	
	
	return 0;
}	



